
<title>修改密码</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a><cite>修改密码</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">修改密码</div>
                <div class="layui-card-body">
                    <div class="layui-form" lay-filter="change_password">
                        <div class="layui-form-item">
                            <label class="layui-form-label" >当前密码</label>
                            <div class="layui-input-inline" style="float: left; margin-left: 10px;">
                                <input type="password" id="oldPassword" name="oldPassword" class="layui-input" lay-verify="required" >
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label" >新密码</label>
                            <div class="layui-input-inline" style="float: left; margin-left: 10px;">
                                <input type="password" id="newPassword" name="newPassword" class="layui-input" lay-verify="required" >
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label" >确认密码</label>
                            <div class="layui-input-inline" style="float: left; margin-left: 10px;">
                                <input type="password" id="newPassword_2" name="newPassword_2" class="layui-input" lay-verify="required" >
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block" >
                                <button class="layui-btn" lay-submit lay-filter="submit_change_password">确认修改</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['form','laydate'], function () {
        var form = layui.form,
            $ = layui.$;

        form.on('submit(submit_change_password)', function (data) {
            data = data.field;
            if (data.newPassword !== data.newPassword_2) {
                layer.msg("两次密码不一致");
                return;
            }

            layer.confirm("确认修改", function (index) {
                var load = layer.load(2);
                $.ajax({
                    url: '/change_password',
                    dataType:   'json',
                    type:       'POST',
                    data:        {'oldPassword': data.oldPassword, 'newPassword': data.newPassword},
                    complete:   function (result) {
                        layer.close(load);
                        result = result.responseJSON;
                        var status = result.status;
                        if (status === 200) {
                            layer.msg("修改成功");
                        }else{
                            layer.msg(result.message);
                        }
                    }
                });
                layer.close(index);
            })

        });
    });
</script>